<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>

    <link href="plugins/kindeditor/themes/simple/simple.css" type="text/css" rel="stylesheet">
    <link href="plugins/kindeditor/themes/default/default.css" rel="stylesheet">
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="goods/specEdit.do" name="goodsForm" id="goodsForm" method="post">
                            <div id="zhongxin" style="padding-top: 13px;">
                                <input type="hidden" id="specId" name="specId" value="${pd.specId}"/>
                                <input type="hidden" id="pic" value="${spec.pic}"/>
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <c:if test="${la !=null}">
                                            <c:forEach var="t" items="${la}" varStatus="i">
                                                <th class="center">${t.labelName}</th>
                                            </c:forEach>
                                        </c:if>
                                        <th class="center">商品名称</th>
                                        <th class="center">商品编码</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:if test="${la !=null}">
                                        <c:forEach var="t" items="${la}" varStatus="i">
                                            <td class="center">${t.attrName}</td>
                                        </c:forEach>
                                    </c:if>
                                    <td class="center">${spec.goodsName}</td>
                                    <td class="center">${spec.code}</td>
                                    </tbody>
                                </table>
                                <table id="table_report1" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">库存:</td>
                                        <td><input type="number" name="realStockNum" id="realStockNum"
                                                   value="${spec.realStockNum }" maxlength="11" min="0"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">进货价:</td>
                                        <td><input type="text" name="bidPrice" id="bidPrice" value="${spec.bidPrice }"
                                                   maxlength="11" style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">销售价:</td>
                                        <td><input type="text" name="price" id="price" value="${spec.price }"
                                                   maxlength="11" style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">最低起售数量:</td>
                                        <td><input type="number" name="minShopNum" id="minShopNum"
                                                   value="${spec.minShopNum }" maxlength="11" min="0"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">最高起售数量:</td>
                                        <td><input type="number" name="maxShopNum" id="maxShopNum"
                                                   value="${spec.maxShopNum }" maxlength="11" min="0"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">库存警告:</td>
                                        <td><input type="number" name="stockWarnNum" id="stockWarnNum"
                                                   value="${spec.stockWarnNum }" maxlength="11" min="0"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 30px; text-align: right; padding-top: 13px;">销售时间:
                                        </td>
                                        <td><span class="dib vm">上架时间:&nbsp;</span><input
                                                id="startTime" name="startTime"
                                                placeholder="请选择上架时间"
                                                value="${spec.startTime }"/>&emsp;&emsp; <span
                                                class="dib vm">下架时间 :&nbsp;</span><input
                                                class="dib vm" id="endTime" name="endTime"
                                                placeholder="请选择下架时间 " value="${spec.endTime }"/></td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 30px; text-align: right; padding-top: 13px;">收获时间:
                                        </td>
                                        <td><span class="dib vm">预计收获时间:&nbsp;</span><input id="harvestTime"
                                                                                            name="harvestTime"
                                                                                            placeholder="请选择预计收获时间"
                                                                                            value="${spec.harvestTime }"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 30px; text-align: right; padding-top: 13px;">果树状态:
                                        </td>
                                        <td><select
                                                class="dib"
                                                name="fruitTreeState" id="fruitTreeState"
                                                data-placeholder="果树状态"
                                                style="vertical-align: top;width: 98%;">
                                            <option value="01"
                                                    <c:if test='${spec.fruitTreeState eq 01}'>selected=selected</c:if>>
                                                树苗
                                            </option>
                                            <option value="00"
                                                    <c:if test='${spec.fruitTreeState eq 00}'>selected=selected</c:if>>
                                                种子
                                            </option>
                                            <option value="02"
                                                    <c:if test='${spec.fruitTreeState eq 02}'>selected=selected</c:if>>
                                                果树
                                            </option>
                                        </select></td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 79px; text-align: right; padding-top: 13px;">展示图片:
                                        </td>
                                        <td><a href="javascript:void(0)"
                                               class="picFileUpload">上传图片</a> <input
                                                type="hidden" id="picture" name="picture"
                                                value="${spec.picture }"/></td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 79px; text-align: right; padding-top: 13px;">还原图片:
                                        </td>
                                        <td>
                                            <a href="javascript:void(0)" class="reduction">一键还原 </a>
                                            &nbsp;&nbsp;&nbsp;(商品图片)
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                            <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>

                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
                                    src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- inline scripts related to this page -->
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<script type="text/javascript" src="static/js/common/file_upload.js"></script>
<script type="text/javascript" src="plugins/kindeditor/kindeditor-all.js"></script>
<script type="text/javascript" src="plugins/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="static/laydate/laydate.js"></script>
<script type="text/javascript" src="static/js/provincial.municipal.league.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
    //页面初始化完毕后执行此方法
    $(function () {
        TAOTAO.kingEditorParams = {
            //指定上传文件参数名称
            filePostName: "uploadFile",
            //指定上传文件请求的url。
            uploadJson: '<%=basePath%>pic/upload',
            //上传类型，分别为image、flash、media、file
            dir: "image",
            extraFileUploadParams: {isCom: "01", width: 800, height: 800, quality: 0.8, end: "view"}
        }

        TAOTAO.kingEditorAutoParams = {
            //指定上传文件参数名称
            filePostName: "uploadFile",
            //指定上传文件请求的url。
            uploadJson: '<%=basePath%>pic/upload',
            //上传类型，分别为image、flash、media、file
            dir: "image",
            extraFileUploadParams: {isCom: "01", width: 200, height: 200, quality: 1, end: "thumb"}
        }

    });
    TAOTAO.initPicUpload($("input[name=picture]").val());
    $('body').on('click', '.imageButton', function () {
        var id = $("#id").val();
        var picture = $("#picture").val();
        var imgsrc = $(this).parent('li').find("img").attr("src");
        var _this = $(this);
        var newPicture = "";
        if (picture.indexOf((imgsrc + ',')) > -1) {
            newPicture = picture.replace((imgsrc + ','), '');
        } else if (picture.indexOf((',' + imgsrc)) > -1) {
            newPicture = picture.replace((',' + imgsrc), '');
        }
        $.ajax({
            url: "<%=basePath%>pic/pictureDelete",
            type: "post",
            async: true,
            dataType: "text",
            data: {"id": id, "newPicture": newPicture, "imgsrc": imgsrc},
            success: function (data) {
                if (data != null) {
                    _this.parent('li').remove();
                    $("#picture").val(newPicture);
                }
                alert(message);
            }, error: function (XMLHttpRequest, textStatus) {
                alealert(textStatus);
            }
        });
    });
    var startTime = {
        elem: '#startTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: true,
        choose: function (datas) {
            endTime.min = datas; //开始日选好后，重置结束日的最小日期
            endTime.start = datas //将结束日的初始值设定为开始日
        }
    };

    var endTime = {
        elem: '#endTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: true,
        choose: function (datas) {
            startTime.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    var harvestTime = {
        elem: '#harvestTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: true,
        choose: function (datas) {
        }
    };
    laydate(startTime);
    laydate(endTime);
    laydate(harvestTime);

    $(".reduction").click(function () {
        var pic = $("#pic").val();
        $("#picture").val(pic);
        TAOTAO.initPicUpload($("input[name=picture]").val());
    });

    function save() {
        if ($.trim($("#realStockNum").val()) == "") {
            alert("请输入库存!")
            return false;
        }
        if ($.trim($("#bidPrice").val()) == "") {
            alert("请输入进货价!")
            return false;
        }
        if ($.trim($("#price").val()) == "") {
            alert("请输入销售价!")
            return false;
        }
        if ($.trim($("#minShopNum").val()) == "") {
            alert("请输入最低起售数量!")
            return false;
        }
        if ($.trim($("#maxShopNum").val()) == "") {
            alert("请输入最高起售数量!")
            return false;
        }
        if ($.trim($("#maxShopNum").val()) <= $.trim($("#minShopNum").val())) {
            alert("最高起售数量要大于最低起售数量")
            return false;
        }
        $("#goodsForm").submit();
        $("#zhongxin").hide();
        $("#zhongxin2").show();
    }
</script>
</html>